use yew::{html, Html};
use yew_router::prelude::{ Redirect};
use yew_router::{Routable};
use crate::business::page::login_page::{LoginPage};
use crate::business::page::session_message_page::SessionMessagePage;
use crate::business::page::user_group_page::{UserGroupPage};
use crate::business::page::fragment::demo_view::Demo;
use crate::business::layout::main_layout::{BlankLayout, MainLayout};
use crate::business::page::index_page::IndexPage;

#[derive(Clone, Routable, PartialEq)]
pub enum ImRoute {
    #[at("/")]
    Index,
    #[at("/main")]
    MainRoot,
    #[at("/main/*")]
    Main,
    #[at("/blank")]
    BlankRoot,
    #[at("/blank/*")]
    Blank,
    #[at("/demo")]
    Demo,
    #[at("/toLogin")]
    ToLogin,
    #[not_found]
    #[at("/404")]
    NotFound,
}

pub fn root_switch(routes: ImRoute) -> Html {
    match routes {
        ImRoute::Index => html! { <LoginPage/> },
        ImRoute::Main | ImRoute::MainRoot => html! { <MainLayout/>},
        ImRoute::Blank | ImRoute::BlankRoot => html! { <BlankLayout/>},
        ImRoute::Demo => html! { <Demo/> },
        ImRoute::ToLogin => html! { <Redirect<ImBlankRoute> to={ImBlankRoute::Login}/> },
        ImRoute::NotFound => html! { <h1>{ "404" }</h1> },
    }
}

#[derive(Clone, Routable, PartialEq)]
pub enum ImBlankRoute {
    #[at("/blank/login")]
    Login,
}

pub fn blank_switch(routes: ImBlankRoute) -> Html {
    match routes {
        ImBlankRoute::Login => html! {<LoginPage/>},
    }
}

#[derive(Clone, Routable, PartialEq)]
pub enum ImMainRoute {
    #[at("/main")]
    Index,

    #[at("/main/user")]
    User,

    #[at("/main/message")]
    Message,
}

pub fn main_switch(route: ImMainRoute) -> Html {

    match route {
        ImMainRoute::Index => html! {
             <IndexPage/>
        },
        ImMainRoute::User => html! {
            <UserGroupPage/>
        },
        ImMainRoute::Message => html! {
            <SessionMessagePage/>
        }
    }
}